home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / amyboard / amiga / amygamelist.c < prev    next >
C/C++ Source or Header  |  1995-08-12  |  8KB  |  314 lines

  1. /*
  2.  * amygamelist.c -- Game list window, part of Amiga front end for XBoard
  3.  * $Id: xgamelist.c,v 1.2 1995/06/26 04:22:40 mann Exp $
  4.  *
  5.  * Copyright 1995 Free Software Foundation, Inc.
  6.  *
  7.  * The following terms apply to the enhanced version of XBoard distributed
  8.  * by the Free Software Foundation:
  9.  * ------------------------------------------------------------------------
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23.  * ------------------------------------------------------------------------
  24.  *
  25.  * See the file ChangeLog for a revision history.
  26.  */
  27.  
  28. #include "AmyBoard.h"
  29.  
  30. #ifndef LIBRARIES_IFFPARSE_H
  31. #include <libraries/iffparse.h>
  32. #endif
  33.  
  34.  
  35.  
  36. Object* gameListUp = NULL;      /*  game list window    */
  37. Object* gameListList = NULL;    /*  list object         */
  38.  
  39.  
  40. /***  Game List callback
  41. ***
  42. ***  Called from the game list window, if user selects a game or
  43. ***  hits a window.
  44. ***
  45. ***  Inputs:    hook - pointer to gameListCallbackHook
  46. ***             win - gamelist window
  47. ***             args - va_list with following arguments:
  48. ***
  49. ***                 action - one of the following constants:
  50. ***                     GAMELIST_LOAD
  51. ***                     GAMELIST_NEXT
  52. ***                     GAMELIST_PREV
  53. ***                     GAMELIST_CLOSE
  54. ***                 listObj - pointer to list object
  55. ***                 fp - FILE pointer to open file
  56. ***                 fileName - string with name of open file
  57. ***
  58. **/
  59. #define GAMELIST_LOAD   0
  60. #define GAMELIST_NEXT   1
  61. #define GAMELIST_PREV   -1
  62. #define GAMELIST_CLOSE  2
  63.  
  64. _HOOK_FUNC(VOID, gameListCallback, struct Hook *hook,
  65.                    Object *gameListUp,
  66.                    va_list args)
  67. {
  68.     int index;
  69.     int offset;
  70.     ListGame* lg;
  71.     FILE* fp;
  72.     char* fileName;
  73.  
  74.     if ((offset = va_arg(args, int))  ==  GAMELIST_CLOSE) {
  75.     GameListPopDown();
  76.     return;
  77.     }
  78.     fp = va_arg(args, FILE*);
  79.     fileName = va_arg(args, char*);
  80.  
  81.     get(gameListList, MUIA_List_Active, &index);
  82.     if (index == MUIV_List_Active_Off) {
  83.     DisplayError("No game selected", 0);
  84.     return;
  85.     }
  86.  
  87.     DoMethod(gameListList, MUIM_List_GetEntry, index+offset, &lg);
  88.     if (!lg) {
  89.     if (offset == GAMELIST_NEXT) {
  90.         DisplayError("Can't go forward any further", 0);
  91.     } else if (offset == GAMELIST_PREV) {
  92.         DisplayError("Can't back up any further", 0);
  93.     }
  94.     }
  95.  
  96.     set(gameListList, MUIA_List_Active, index+offset);
  97.  
  98.     if (cmailMsgLoaded) {
  99.     CmailLoadGame(fp, lg->number, fileName, TRUE);
  100.     } else {
  101.     LoadGame(fp, lg->number, fileName, TRUE);
  102.     }
  103. }
  104. struct Hook gameListCallbackHook = {
  105.     { NULL, NULL },
  106.     (HOOKFUNC) gameListCallback,
  107.     NULL,
  108.     NULL
  109. };
  110. /**/
  111.  
  112.  
  113. /***  GameListPopUp() function
  114. ***
  115. ***  Brings up a requester with the list of games. Receives following
  116. ***  arguments:
  117. ***
  118. ***     proc    Function to call, if user has selected a game
  119. ***     fp      File to load the game from; will be closed, if the
  120. ***             user cancels.
  121. ***     title   title to display
  122. **/
  123.  
  124. _HOOK_FUNC(ULONG, gameListDisp, struct Hook *hook,  /*  Called to display  */
  125.                 char **strArray,    /*  one game           */
  126.                 ListGame *lg)
  127. {
  128.     static char buf[20];
  129.  
  130.     sprintf(buf, "%d", lg->number);
  131.     *strArray++ = buf;
  132.     *strArray++ = lg->gameInfo.event;
  133.     *strArray++ = lg->gameInfo.white;
  134.     *strArray++ = lg->gameInfo.black;
  135.  
  136.     return(0);
  137. }
  138. struct Hook gameListDispHook = {
  139.     { NULL, NULL },
  140.     (HOOKFUNC) gameListDisp,
  141.     NULL,
  142.     NULL
  143. };
  144.  
  145.  
  146. void GameListPopUp(FILE *fp, char *fileName)
  147.  
  148. {
  149.     Object* loadButton;
  150.     Object* nextButton;
  151.     Object* prevButton;
  152.     Object* cancelButton;
  153.     char *file;
  154.     int open;
  155.  
  156.     if (!(file = strdup(fileName))) {
  157.     DisplayError("Cannot open file.", 0);
  158.     return;
  159.     }
  160.  
  161.     if (!gameListUp) {
  162.     /* Create window. */
  163.     gameListUp = WindowObject,
  164.             MUIA_Window_ID, MAKE_ID('G','L','S','T'),
  165.             MUIA_Window_Title, "Game list requester",
  166.             MUIA_Window_RefWindow, xboardWindow,
  167.             WindowContents, VGroup,
  168.             Child, gameListList = ListviewObject,
  169.                 MUIA_Listview_List, ListObject,
  170.                 MUIA_List_DisplayHook, &gameListDispHook,
  171.                 /* Display 4 columns, the second one (event)
  172.                  * is the most important.
  173.                  */
  174.                 MUIA_List_Format, "WEIGHT=25,WEIGHT=200,WEIGHT=100,WEIGHT=100",
  175.                 InputListFrame,
  176.                 End,
  177.             End,
  178.             Child, HGroup,
  179.                 Child, loadButton = MUI_MakeObject(MUIO_Button, "Ok"),
  180.                 Child, HSpace(0),
  181.                 Child, nextButton = MUI_MakeObject(MUIO_Button, "Next"),
  182.                 Child, HSpace(0),
  183.                 Child, prevButton = MUI_MakeObject(MUIO_Button, "Prev"),
  184.                 Child, HSpace(0),
  185.                 Child, cancelButton = MUI_MakeObject(MUIO_Button, "Close"),
  186.             End,
  187.             End,
  188.         End;
  189.  
  190.     if (!gameListUp) {
  191.         DisplayError("Cannot open window", ENOMEM);
  192.         return;
  193.     }
  194.  
  195.  
  196.     DoMethod(xboardApp, OM_ADDMEMBER, gameListUp);
  197.  
  198.     /* Setup hooks to call, if user closes window, selects game or hits
  199.      * a button.
  200.      */
  201.     DoMethod(gameListUp, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  202.          gameListUp, 3, MUIM_CallHook, &gameListCallbackHook,
  203.          /* Hook arguments */
  204.          GAMELIST_CLOSE);
  205.     DoMethod(gameListList, MUIM_Notify, MUIA_Listview_DoubleClick, TRUE,
  206.          gameListUp, 5, MUIM_CallHook, &gameListCallbackHook,
  207.          /* Hook arguments */
  208.          GAMELIST_LOAD, fp, file);
  209.     DoMethod(loadButton, MUIM_Notify, MUIA_Pressed, FALSE,
  210.          gameListUp, 5, MUIM_CallHook, &gameListCallbackHook,
  211.          /* Hook arguments */
  212.          GAMELIST_LOAD, fp, file);
  213.     DoMethod(nextButton, MUIM_Notify, MUIA_Pressed, FALSE,
  214.          gameListUp, 5, MUIM_CallHook, &gameListCallbackHook,
  215.          /* Hook arguments */
  216.          GAMELIST_NEXT, fp, file);
  217.     DoMethod(prevButton, MUIM_Notify, MUIA_Pressed, FALSE,
  218.          gameListUp, 5, MUIM_CallHook, &gameListCallbackHook,
  219.          /* Hook arguments */
  220.          GAMELIST_PREV, fp, file);
  221.     DoMethod(cancelButton, MUIM_Notify, MUIA_Pressed, FALSE,
  222.          gameListUp, 3, MUIM_CallHook, &gameListCallbackHook,
  223.          /* Hook arguments */
  224.          GAMELIST_CLOSE);
  225.     }
  226.  
  227.     set(gameListList, MUIA_List_Quiet, TRUE);
  228.     DoMethod(gameListList, MUIM_List_Clear);
  229.     {
  230.     ListGame *lg;
  231.  
  232.     for (lg = (ListGame *) gameList.head;
  233.          lg->node.succ;
  234.          lg = (ListGame *) lg->node.succ) {
  235.         DoMethod(gameListList, MUIM_List_InsertSingle, lg, MUIV_List_Insert_Bottom);
  236.     }
  237.     }
  238.     set(gameListList, MUIA_List_Quiet, FALSE);
  239.     set(gameListUp, MUIA_Window_Open, TRUE);
  240.     get(gameListUp, MUIA_Window_Open, &open);
  241.  
  242.     if (!open) {
  243.     DisplayError("Cannot open window: ", ENOMEM);
  244.     }
  245. }
  246. /**/
  247.  
  248.  
  249. /***  ShowGameListProc() function
  250. ***
  251. ***  Called from the menu, if user selects the "Show Game List" item.
  252. **/
  253. void ShowGameListProc(void)
  254.  
  255. {
  256.     int open;
  257.  
  258.     if (!gameListUp) {
  259.     DisplayError("There is no game list", 0);
  260.     return;
  261.     }
  262.  
  263.     get(gameListUp, MUIA_Window_Open, &open);
  264.     set(gameListUp, MUIA_Window_Open, !open);
  265. }
  266. /**/
  267.  
  268.  
  269. /***  GameListPopDown() function
  270. ***
  271. ***  Removes the game list window temporarily.
  272. **/
  273. void GameListPopDown(void)
  274.  
  275. {
  276.     if (!gameListUp) {
  277.     return;
  278.     }
  279.     set(gameListUp, MUIA_Window_Open, FALSE);
  280. }
  281. /**/
  282.  
  283.  
  284. /***  GameListDestroy() function
  285. ***
  286. ***  Removes the game list window finally.
  287. **/
  288. void GameListDestroy(void)
  289.  
  290. {
  291.     if (!gameListUp) {
  292.     return;
  293.     } else {
  294.     CloseMuiWindow(gameListUp);
  295.     gameListUp = NULL;
  296.     }
  297. }
  298. /**/
  299.  
  300.  
  301. /***  GameListHighLight() function
  302. ***
  303. ***  Highlights a certain entry in the game list.
  304. ***
  305. ***  Inputs:    index - number of entry to highlight
  306. **/
  307. void GameListHighlight(int index)
  308.  
  309. {
  310.     if (gameListUp) {
  311.     set(gameListList, MUIA_List_Active, index-1);
  312.     }
  313. }
  314.